/**
 * 
 */

 $(function() {  
        var websocket;  
        if ('WebSocket' in window) {  
            console.info("WebSocket");  
          /*  var url = 'ws://' + window.location.host + '/webinfomgr/websocket';  
            websocket = new WebSocket(url);  */
            websocket = new ReconnectingWebSocket('ws://' + window.location.host + '/webinfomgr/websocket', null, {debug:true, maxReconnectAttempts:4});
            //websocket = new WebSocket("ws://127.0.0.1:8080/SSMTest/echo");  
        } else if ('MozWebSocket' in window) {  
            console.info("MozWebSocket");  
            websocket = new MozWebSocket("ws://websocket");  
        } else {  
            console.info("SockJS");  
            websocket = new SockJS("http://127.0.0.1:8080/webinfomgr/sockjs/websocket");  
        }  
        websocket.onopen = function(evnt) {  
            $("#tou").html("链接服务器成功!");  
        };  
        websocket.onmessage = function(evnt) {  
            $("#msg").html($("#msg").html() + "<br/>" + evnt.data);  
        };  
        websocket.onerror = function(evnt) {  
        };  
        websocket.onclose = function(evnt) {  
            $("#tou").html("与服务器断开了链接!")  
        }  
        $('#send').bind('click', function() {  
            send();  
        });  
        function send() {  
            if (websocket != null) {  
                var message = document.getElementById('username').value;  
                websocket.send(message);  
            } else {  
                console.info('未与服务器链接.');  
            }  
        }  
    });  